﻿using Newtonsoft.Json;
using System.ComponentModel;
using System.Windows;
using VisionDesigner.ColorConvert;
using VM.Common.Enums;
using VM.Common.Helper;


namespace Plugin.ColorConvert
{
    [JsonObject(MemberSerialization.OptIn)]
    public class ParamModel : NotifyPropertyBase
    {

        private Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {

            { "RGB转灰度", "RGB2GRAY" },
            { "RGB转HSV", "RGB2HSV" },
            { "RGB转HSI", "RGB2HSI" },
            { "RGB转YUV", "RGB2YUV" },
             { "通用转换比例", "GeneralRatio" },
              { "平均转换比例", "AverageRatio" },
               { "通道最小值", "ChannelMin" },
                   { "通道最大值", "ChannelMax" },
                       { "R通道", "RChannel" },
                  { "G通道", "GChannel" },
                   { "B通道", "BChannel" },

                   { "第一通道", "R" },
                  { "第二通道", "G" },
                   { "第三通道", "B" },

        };



        // 颜色转换类型
        private List<string> _ColorConvertArray = EnumHelper.GetEnumDescriptions<ConvertTypes>();
        public List<string> ColorConvertArray
        {
            get { return _ColorConvertArray; }
            set { Set(ref _ColorConvertArray, value); }
        }
        //形状数组
        private List<string> _RGB2GrayArray = EnumHelper.GetEnumDescriptions<Shape>();
        public List<string> RGB2GrayArray
        {
            get { return _RGB2GrayArray; }
            set { Set(ref _RGB2GrayArray, value); }
        }
        //通道数组
        private List<string> _ChannelArray = EnumHelper.GetEnumDescriptions<ChannelTypes>();
        public List<string> ChannelArray
        {
            get { return _ChannelArray; }
            set { Set(ref _ChannelArray, value); }
        }


        //类型选择
        [Newtonsoft.Json.JsonRequired]
        public string _ColorConverType = EnumHelper.GetEnumDescription(ConvertTypes.RGB2GRAY);
        public string ColorConverType
        {
            get { return _ColorConverType; }
            set
            {
                Set(ref _ColorConverType, value);
                UpdateThresholdVisible();
            }
        }
        //RGB转灰度选择
        [Newtonsoft.Json.JsonRequired]
        public string _ShapeType = EnumHelper.GetEnumDescription(Shape.AverageRatio);
        public string ShapeType
        {
            get { return _ShapeType; }
            set
            {
                Set(ref _ShapeType, value);

            }
        }
        //通道数选择
        [Newtonsoft.Json.JsonRequired] public string _ChannelType = EnumHelper.GetEnumDescription(ChannelTypes.R);
        public string ChannelType
        {
            get { return _ChannelType; }
            set { Set(ref _ChannelType, value); }
        }
        private Visibility _Xingzhuang = Visibility.Visible;
        public Visibility Xingzhuang
        {
            get { return _Xingzhuang; }
            set { Set(ref _Xingzhuang, value); }
        }

        private Visibility _Channels = Visibility.Collapsed;
        public Visibility Channels
        {
            get { return _Channels; }
            set { Set(ref _Channels, value); }
        }


        private Dictionary<string, object> _paramEnum = new Dictionary<string, object>();
        public Dictionary<string, object> ParamEnum
        {
            get { return _paramEnum; }
            set { Set(ref _paramEnum, value); }
        }



        // 整型
        private Dictionary<string, int> _paramInt = new Dictionary<string, int>();
        public Dictionary<string, int> ParamInt
        {
            get { return _paramInt; }
            set
            {
                Set(ref _paramInt, value);

            }

        }

        //二值化
        public void Morupdata(CColorConvertTool cImageMor)
        {//形态学方式
            cImageMor.SetRunParam("ColorTransformType", ParamMap[ColorConverType]);
            //形状
            cImageMor.SetRunParam("RGB2GrayType", ParamMap[ShapeType]);



        }



        private void UpdateThresholdVisible()
        {
            switch (ColorConverType)
            {
                case "RGB转灰度":

                    Xingzhuang = Visibility.Visible;
                    Channels = Visibility.Collapsed;
                    break;
                case "RGB转HSV":

                    Xingzhuang = Visibility.Collapsed;
                    Channels = Visibility.Visible;
                    break;
                case "RGB转HSI":

                    Xingzhuang = Visibility.Collapsed;
                    Channels = Visibility.Visible;
                    break;
                case "RGB转YUV":
                    Channels = Visibility.Visible;
                    Xingzhuang = Visibility.Collapsed;
                    break;

                default:
                    break;
            }
        }


    }


    /// <summary>
    /// 输出图像
    /// </summary>
    [Serializable]
    public enum OutImageTypes
    {
        原图,
        颜色转换图像,

    }

    /// <summary>
    /// 腐蚀方式
    /// </summary>


    public enum ConvertTypes
    {

        [Description("RGB转灰度")]
        RGB2GRAY,

        [Description("RGB转HSV")]
        RGB2HSV,

        [Description("RGB转HSI")]
        RGB2HSI,

        [Description("RGB转YUV")]
        RGB2YUV,

    }

    public enum ChannelTypes
    {

        [Description("第一通道")]
        R,

        [Description("第二通道")]
        G,

        [Description("第三通道")]
        B,


    }

    public enum Shape
    {

        [Description("通用转换比例")]
        GeneralRatio,

        [Description("平均转换比例")]
        AverageRatio,

        [Description("通道最小值")]
        ChannelMin,

        [Description("通道最大值")]
        ChannelMax,

        [Description("R通道")]
        RChannel,

        [Description("G通道")]
        GChannel,

        [Description("B通道")]
        BChannel,

    }





}
